<? include 'server_config.php'; 

if($_SESSION['user_idx'] == "k")//임시"")
{
	?>
	<script>
		location.href='login.php';
	</script>
	<?
	return;
}
?>

		
			<div style='height:3px;width:100%;float:left;'><span><span></div>
			<div style='height:1px;width:100%;background:#cccccc;float:left;'><span><span></div>

<?

				$sql_count ="
					SELECT COUNT(A.document_idx)
					FROM ndd_document A, ndd_user B
					WHERE A.board_idx = '$board_idx' 
					AND A.user_idx = B.user_idx
					";

				if($category_idx!=0)
					$sql_count .="	AND A.category_idx= ".$category_idx." ";

				if($search_type==1)
					$sql_count .="	AND A.title like '%".$search_input."%' ";
				if($search_type==2)
					$sql_count .="	AND A.content like '%".$search_input."%' ";
				if($search_type==3)
					$sql_count .="	AND ( A.title like '%".$search_input."%' OR A.content like '%".$search_input."%' ) ";
				if($search_type==4)
					$sql_count .="	AND B.nickname like '%".$search_input."%' ";


				$sql_count.="
					;
				";

				$result = mysql_query($sql_count,$connect);
				$row = mysql_fetch_row($result);

				$article_count = $row[0];
?>
				<script>
				$('#article_count').html('<?=$article_count?>');
				</script>

<?

			

				$sql="
					SELECT A.document_idx, A.title, A.category_idx, A.read_count, B.nickname, A.recommend_count, A.accuse_count, A.reg_timestamp, C.name, A.comment_count, A.user_idx, A.content
					FROM ndd_document A, ndd_user B, ndd_category C					
					WHERE A.board_idx = '$board_idx' 
					AND A.user_idx = B.user_idx
					AND A.category_idx = C.category_idx 
					";

				if($category_idx!=0)
					$sql .="	AND A.category_idx= ".$category_idx." ";

				if($search_type==1)
					$sql .="	AND A.title like '%".$search_input."%' ";
				if($search_type==2)
					$sql .="	AND A.content like '%".$search_input."%' ";
				if($search_type==3)
					$sql .="	AND ( A.title like '%".$search_input."%' OR A.content like '%".$search_input."%' ) ";
				if($search_type==4)
					$sql .="	AND B.nickname like '%".$search_input."%' ";

				$sql.="
					ORDER BY A.reg_timestamp DESC LIMIT ".($page)*$article_per_page.";
				";

				$result = mysql_query($sql,$connect);

				$i=0;

				while($row = mysql_fetch_row($result))
				{
					if($i==0 && $page==1)
					{
						$document_idx = $row[0];
						?>
						<script>
							
							//setTimeout('talk_display_article(<? echo $row[0];?>);',10);
							$(document).ready(function(){ talk_display_article(<? echo $row[0];?>); });
						</script>
						<?
					}
					$i++;
			
?>


			<div style='height:99px;width:100%;float:left;cursor:pointer;' onmouseover="style.background='#F2F2F2';$('#list_arrow_<? echo $row[0];?>').show();" onmouseout="style.background='#FFFFFF';$('#list_arrow_<? echo $row[0];?>').hide();" onclick='talk_display_article(<? echo $row[0];?>);'>
				<div style='height:15px;width:100%;float:left;'><span>
					<!--div style='height:35px;width:35px;position:absolute;background:red;'><span></span></div-->
				</span></div>
				<div style='height:84px;width:65px;float:left;'>
					<div style='height:84px;width:14px;float:left;'></div>
					<div style='height:38px;width:38px;float:left;background:yellow;'>
					
					
						<?
							$document_user_idx=$row[10];
							$user_img = "./upload/member_photo/".$document_user_idx;

							if(file_exists($user_img)){
						?>
							<img src="<? echo $user_img; ?>" width="38px" height="38px" border=0>
						<?
							}
							else
							{
						?>
							<? if($document_user_idx == $_SESSION['user_idx'])
								{
							?>
								<a href="member_info.php">이미지등록</a>
							<?
								}
							?>
						<?
							}
						?>					
					
					</div>
				</div>
				<div style='height:84px;width:140px;float:left;'>
					<span id='list_id'><? echo $row[4]; //글쓴이?></span>
					<span id='list_id_detail'><br>
						<? 
						
							$sql_2="
								SELECT birthday, sex FROM ndd_user_expand WHERE user_idx = $document_user_idx LIMIT 1;
							";
									
							$result_2 = mysql_query($sql_2,$connect);
				
							$row2 = mysql_fetch_row($result_2);

							if($row2[1]=="M")
								echo "남";
							else if($row[1]=="F")
								echo "여";
							else 
								echo "(미입력)";
							
							echo " / ";

							if($row[0]!="0000-00-00" && $row2[0]!="")
							{

								//생일 입력
								$myBirthDate    = strtotime($row2[0]);

								//만나이
								$birthDate1     = date( 'Ymd', $myBirthDate );
								$nowDate1       = date('Ymd');
								$age1           = floor(($nowDate1 - $birthDate1) / 10000);

								//한국 나이
								$birthDate2     = date( 'Y', $myBirthDate );
								$nowDate2       = date('Y');
								$age2           = $nowDate2 - $birthDate2 + 1 ;

								echo $age2."세";
							}
							else
							{
								echo "(미입력)";

							}
				
						?>

						<br>
						류마 점수 3점<br>

					</span>
				</div>
				<div style='height:54px;width:310px;float:left;'>
					<span id='list_article_title'><? echo iconv_substr($row[1],0,30,"UTF-8"); //제목?>...<? //echo $row[5]; //추천수?><br></span>
					<span id='list_article_content'>
					<? echo iconv_substr($row[11],0,60,"UTF-8");
// substr($row[11],0,120); //내용?>...<br>
					</span>


				</div>
				<div style='height:54px;width:50px;float:left;display:none;' id='list_arrow_<? echo $row[0];?>'>
					<img src='./img/list_arrow.jpg'>
					
				</div>
				<div style='height:30px;width:310px;float:left;'>
					<span id='list_article_title'>
						<? //echo $row[7]; //등록시각?>
						<span id="date_<? echo $row[0];?>">
						</span>
						<script>
							$('#date_<? echo $row[0];?>').text( getDateStr(<? echo substr($row[7],0,4); ?>, <? echo substr($row[7],5,2); ?>, <? echo substr($row[7],8,2); ?>, <? echo substr($row[7],11,2); ?>, <? echo substr($row[7],14,2); ?>, <? echo substr($row[7],17,2); ?>) );
						</script>
					</span>
				</div>
			

			</div>
			<div style="height:1px;width:100%;background-image:url('./img/line_dot.png');float:left;"><span><span></div>
<?
				}
?>

<? //echo $article_count." ".(($page-1)*10); ?>
<?
	if ($article_count>(($page)*$article_per_page) )
	{
?> 
			<div style='height:30px;width:100%;float:left;'><span></span></div>
			<div style='float:left;height:50px;width:100%;text-align:center;'><span>
			<img id="img_show_more" src="./img/talk_view_more.png" alt="더보기" style="cursor:pointer;border:0px;" onclick="talk_display_list('<? echo $board_idx;?>','<? echo $board_name;?>','<? echo $category_idx;?>','<? echo $page+1;?>' ); " />
			</span>
			</div>
			<div style='height:30px;width:100%;float:left;'><span></span></div>
		
	<?
	}
	else
	{
	?>
			<div style='height:30px;width:100%;float:left;'><span></span></div>
			
			<div style='height:60px;width:100%;float:left;text-align:center;'>
			마지막 페이지 입니다.</div>
	<?
	}
	?>

<br><br>
		